package br.usp.ime.lab.main;
import java.util.Vector;

import br.usp.ime.instrumentation.Instrumentation;
import br.usp.ime.lab.analyzer.ConditionAnalyzerImpl;
import recoder.ParserException;
import recoder.abstraction.Method;
import recoder.java.ProgramElement;
import recoder.java.declaration.ClassDeclaration;

public class Main {
	
	public static void doInstrumentation(String sourcePackage, String instrumentedPackage) {
		ConditionAnalyzerImpl ca = new ConditionAnalyzerImpl();
		Vector<Method> metodos = ca.getAst(sourcePackage, "");
		
		ca.getAllDecisions(sourcePackage + "/../" + "decisoes.xml", metodos.elementAt(0));
		ca.getAllConditions(sourcePackage + "/../" + "condicoes.xml", metodos.elementAt(0));
		// MC/DC
		for (Method m : metodos) {
			ProgramElement p = (ProgramElement)m;
			ClassDeclaration className;
			while (!(p.getASTParent() instanceof ClassDeclaration)) {
				p = p.getASTParent();
			}
			className = (ClassDeclaration) p.getASTParent();
			String filename = sourcePackage + "/../" + "mcdc_" + className.getName() + "_" + m.getName() + ".xml";
			ca.getAllMCDC(filename, m);		
		}
		try {
			Instrumentation.getInstance().instrumentatePackage(sourcePackage, "", instrumentedPackage);
		} catch (ParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
